package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.result.PageBean;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import com.sky.websocket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
public class OrderController {

    @Autowired
    OrderService orderService;


    //用户下单
    @PostMapping("/submit")
    public Result submitOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        //1.接收参数
        log.info("用户下单{}", ordersSubmitDTO);
        //2.处理请求
        OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
        // 3。 封装结果
        return Result.success(orderSubmitVO);
    }

    //查询历史订单
    @GetMapping("/historyOrders")
    public Result getHistoryOrders(OrdersPageQueryDTO ordersPageQueryDTO) {
        //1.接收参数
        log.info("历史订单查询");
        //2.
        PageBean pageBean = orderService.ordersHistory(ordersPageQueryDTO);
        return Result.success(pageBean);
    }

    //查询订单详情
    @GetMapping("/orderDetail/{id}")
    public Result getOrderDetailById(@PathVariable Long id) {
        // 1.查询两张表
        OrderVO orderVO = orderService.getOrderById(id);
        return Result.success(orderVO);
    }

    //取消订单
    @PutMapping("/cancel/{id}")
    public Result cancelOrder(@PathVariable Long id) {
        orderService.cancelOrderById(id);
        return Result.success();
    }

    //再来一单
    @PostMapping("/repetition/{id}")
    public Result postRepetition(@PathVariable Long id) {
        orderService.postRepetitionById(id);
        return Result.success();

    }

    //用户催单
    @GetMapping("/reminder/{id}")
    public Result getReminder(@PathVariable Long id) {
        orderService.getReminderById(id);
        return Result.success();
    }
}
